package com.yilu.driver.mvp.presenter;

import android.content.Context;
import android.widget.Toast;

import com.is.common.retrofitrxcache.RxCacheResult;
import com.is.common.rx.RxSubscriber;
import com.yilu.driver.DriverConstant;
import com.yilu.driver.entity.TraineeListResponse;
import com.yilu.driver.mvp.contract.TrainInfoListContract;

import org.json.JSONObject;


public class TraineeInfoListPresenter extends TrainInfoListContract.Presenter {
    private Context mContext;

    public TraineeInfoListPresenter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void getTraineeInfoList(final int event_tag, JSONObject json) {
        mRxManager.add(mModel.getTraineeInfoList(json)
                .subscribe(new RxSubscriber<RxCacheResult<TraineeListResponse>>(
                        mContext, "加载中", false) {
                    @Override
                    protected void _onNext(RxCacheResult<TraineeListResponse> loginResponseRxCacheResult) {
                        if (event_tag == DriverConstant.EVENT_REFRESH) {
                            mView.returnTrainListRefresh(loginResponseRxCacheResult.getResultModel());
                        } else if (event_tag == DriverConstant.EVENT_LOADMORE) {
                            mView.returnTrainListLoadMore(loginResponseRxCacheResult.getResultModel());
                        }

                    }

                    @Override
                    protected void _onError(String message) {
                        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
                    }
                }));
    }
}
